<template>
  <view>
    <search-page
      :defaultText="placeholder"
      :hMax="hMax"
      :showHistory="showHistory"
      :hType="hType"
      :oType="oType"
      :focus="focus"
      @search="search"
      class="solid-bottom"
    ></search-page>
    <view class="cu-list menu-avatar padding-sm" v-if="list.length > 0">
      <view class="cu-item bg-gradual-blue margin-bottom-sm" v-for="(item, index) in list" @tap="toChild($event, item)" :data-id="item.id" :data-typeid="item.cid">
        <view class="cu-avatar round lg" :style="'background-image:url(' + item.img + ');'"></view>
        <view class="content">
          <view class="text-white">{{ item.title }}</view>
          <view class="text-sm flex" style="color: #d7d7d7">
            <view class="text-cut">面值：{{ item.mianzhi }}</view>
          </view>
        </view>
        <view class="action">
          <text class="cuIcon cuIcon-right"></text>
        </view>
      </view>
    </view>
    <view class="cu-list menu-avatar padding-sm" v-else>
      <view class="cu-item bg-white margin-bottom-sm">
        <view class="content">
          <view class="text-white">
            <image :src="httpurl + '/static/uniapp/img/empty.png'" mode="aspectFit" style="width: 100%; height: 140rpx"></image>
          </view>
          <view class="text-sm text-center" style="color: #d7d7d7">
            <text>没有找到记录哦~~</text>
          </view>
        </view>
      </view>
    </view>
    <!-- <v-kefu></v-kefu> -->
  </view>
</template>

<script>
let _this = this;
import searchPage from '@/components/search-page/index.vue';
import kefu from '@/components/kefu.vue';
export default {
  components: { searchPage, 'v-kefu': kefu },
  data() {
    return {
      placeholder: '请输入搜索关键词',
      hMax: 10,
      showHistory: true,
      hType: 'round',
      oType: 'square-fill',
      focus: true,
      list: [],
      httpurl: '' //图片链接
    };
  },
  onLoad(ops) {
    _this = this;
    console.log('ops', ops);
    if (ops.keys != null && ops.keys != undefined) {
      this.placeholder = ops.keys;
      console.log('this.placeholder', this.placeholder);
      this.search(this.placeholder);
      this.$forceUpdate();
    }
  },
  onShow() {
    this.httpurl = this.app.httpUrl;
  },
  onHide() {
    uni.removeStorageSync('keyword');
  },
  methods: {
    goToone() {
      uni.navigateBack({
        delta: 1
      });
    },
    search(text) {
      uni.request({
        method: 'post',
        url: _this.app.apiHost + '/sechcard',
        header: { Authorization: '' },
        data: { keys: text },
        success: (data) => {
          console.log(data);
          if (data.data.code == 0) {
            let da = data.data.data;
            console.log(da);
            _this.list = da;
          } else {
            that.app.showMsg('数据错误');
          }
        },
        fail(a) {
          that.app.showMsg('链接失败');
        }
      });
    },
    toChild(e, item) {
      console.log(111, e, item);
      let type = e.currentTarget.dataset.typeid,
        cid = e.currentTarget.dataset.id;
      uni.setStorageSync('cid', cid);
      uni.setStorageSync('typeid', type);
      uni.navigateTo({
        url: '../index/card?cid=' + cid + '&typeid=' + type
      });
    }
  }
};
</script>
<style>
.cu-item {
  height: 180rpx !important;
  line-height: 180rpx;
  border-radius: 10rpx;
}
</style>
